********************************************************************
*This file builds population by education level from the Census/ACS*
********************************************************************

use "$list/czones_list.dta", clear
expand 3
gen year=1990
bys czone: replace year=2000 if _n==2
bys czone: replace year=2008 if _n==3

merge m:1 czone using "$clean_data_lmarket/czone1990_education.dta", assert(3) nogenerate
merge m:1 czone using "$clean_data_lmarket/czone2000_education.dta", assert(3) nogenerate
merge m:1 czone using "$clean_data_lmarket/czone2008_education.dta", assert(3) nogenerate
merge m:1 czone using "$clean_data_lmarket/czone2016_education.dta", assert(3) nogenerate

foreach var of varlist ipums_* {
quiet replace `var' = 0 if mi(`var')
}

*Education groups
foreach educ in b a l  {

gen d_pop_`educ' = 100*0.7*(ipums_pop_`educ'_2000/ipums_pop_2000-ipums_pop_`educ'_1990/ipums_pop_1990) if year == 1990
replace d_pop_`educ' = 100*(ipums_pop_`educ'_2008/ipums_pop_2008-ipums_pop_`educ'_2000/ipums_pop_2000) if year == 2000
replace d_pop_`educ' = 100*(ipums_pop_`educ'_2016/ipums_pop_2016-ipums_pop_`educ'_2008/ipums_pop_2008) if year == 2008

}


*Shift years to match 1990 with 2000 and 2000 with 2008 in analysis
rename (year) (year_normal)

gen year = 1990 if year_normal == 2000
replace year = 2000 if year_normal == 2008

save "$final_data_outcomes/czone_PopulationEducation.dta", replace






